package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.dubbo.api.SettingsApi;
import com.tanhua.dubbo.mapper.SettingMapper;
import com.tanhua.model.domain.Settings;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Author Pan Rundong
 * @Date 2023-02-27 9:45
 * @Desc 设置表Api实现类
 */
@DubboService
public class SettingsApiImpl implements SettingsApi {
    @Autowired
    private SettingMapper settingMapper;

    /**
     * 根据Id查询
     * @Author: Pan Rundong
     * @param userId
     * @return com.tanhua.model.domain.Settings
     */
    @Override
    public Settings getById(Long userId) {
        LambdaQueryWrapper<Settings> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Settings::getUserId, userId);
        Settings settings = settingMapper.selectOne(queryWrapper);
        return settings;
    }

    /**
     * 更改设置
     * @Author: Pan Rundong
     * @param settings
     * @return void
     */
    @Override
    public void update(Settings settings) {
        settingMapper.updateById(settings);
    }

    /**
     * 保存设置
     * @Author: Pan Rundong
     * @param settings
     * @return void
     */
    @Override
    public void save(Settings settings) {
        settingMapper.insert(settings);
    }

}
